package com.example.myapplication;

import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

public class DanChoiceDialogFragment extends DialogFragment {
    private String[] genders = new String[]{"男", "女"};
    private ChoiceDialogFragment.NotifyDialogListener listener;

    public interface NotifyDialogListener {
        public void onDialogPositiveClicked(String gender);
    }

    public void setListener(ChoiceDialogFragment.NotifyDialogListener listener) {
        this.listener = listener;
    }

    public Dialog onCreateDialog(Bundle savedInstanceState) {
      AlertDialog.Builder bulider = new AlertDialog.Builder(getActivity());
      bulider.setTitle("单选对话框")
              .setSingleChoiceItems(genders,0,new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog, int which) {
                      String gender = genders[which];
                  }
        });
      return bulider.create();
    }
}